<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="/WEB-INF/tags/functions.tld" %>
<%@ taglib prefix="t" uri="/WEB-INF/tags/tags.tld" %>
<link rel="stylesheet" href="/css/table.css" type="text/css" media="all" />
<link rel="stylesheet" href="/css/paging.css" type="text/css" media="all" />
<link rel="stylesheet" href="/css/message.css" type="text/css" media="all" />
<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/notify.js"></script>
<link rel="stylesheet" href="/css/jquery.ui.theme.css">
<link rel="stylesheet" href="/css/jquery.ui.core.css" />
<link rel="stylesheet" href="/css/jquery.ui.autocomplete.css" />
<link rel="stylesheet" href="/css/jquery.ui.menu.css" />
<script src="/js/jquery.ui.core.js"></script>
<script src="/js/jquery.ui.widget.js"></script>
<script src="/js/jquery.ui.position.js"></script>
<script src="/js/jquery.ui.menu.js"></script>
<script src="/js/jquery.ui.autocomplete.js"></script>
<script type="text/javascript" src="/js/searchClassAC.js"></script>

<h2 style="margin-left: 2%;">Tìm kiếm lớp học</h2>
<hr size="1" />

<div class="box">
	<h3 class="boxTitle">Tìm kiếm lớp học</h3>
	<form action="/admin/searchClasses.html" method="GET">
		<table style="width: 100%">
			<tr>
				<td>Mã lớp</td>
				<td><input type="text" name="cId" id="cId" class="searchInput" value="${param.cId}" /></td>
				<td>Học phần</td>
				<td><input type="text" name="sId" id="sId" class="searchInput" value="${param.sId}" /></td>
				<td>Giảng viên</td>
				<td><input type="text" name="lId" id="lId" class="searchInput" value="${param.lId}" /></td>
				<td>Học kỳ</td>
				<td>
					<select name="semester" class="searchInput">
						<option value="-1">--Tất cả các học kỳ--</option>
						<c:forEach items="${semesters}" var="s">
							<c:choose>
								<c:when test="${param.semester != null}">
									<c:if test="${s.semesterName == param.semester}">
										<option value="${s.semesterName}" selected="selected">${s.semesterName}</option>
									</c:if>
									<c:if test="${s.semesterName != param.semester}">
										<option value="${s.semesterName}">${s.semesterName}</option>
									</c:if>
								</c:when>
								<c:otherwise>
									<c:if test="${s.current}">
										<option value="${s.semesterName}" selected="selected">${s.semesterName}</option>
									</c:if>
									<c:if test="${!s.current}">
										<option value="${s.semesterName}">${s.semesterName}</option>
									</c:if>
								</c:otherwise>
							</c:choose>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="8"><input type="submit" value="Tìm kiếm" /></td>
			</tr>
		</table>
	</form>
</div>

<c:if test="${msg != null}">
	<div class="notify">
		<c:out value="${msg}" />
	</div>
	<c:remove var="msg" scope="session"/>
</c:if>
<c:if test="${classes == null or empty classes}">
	<b>Không có lớp học</b>
</c:if>
<c:if test="${classes != null and !empty classes}">
	<c:url value="/admin/deleteClasses.html" var="deleteClassesUrl">
		<c:param name="p" value="${pageInfo.currentPage}" />
		<c:param name="cId" value="${param.cId}" />
		<c:param name="sId" value="${param.sId}" />
		<c:param name="lId" value="${param.lId}" />
		<c:param name="semester" value="${param.semester}" />
	</c:url>
	<form action="${deleteClassesUrl}" method="post">
		<table>
			<thead>
				<tr>
					<td class="th" style="width: 1em;"><input type="checkbox" name="checkAll" id="checkAll" /></td>
					<th class="th">STT</th>
					<th class="th">Mã lớp</th>	
					<th class="th">Tên lớp</th>
					<th class="th">Mã học phần</th>
					<th class="th">Giảng viên</th>
					<th class="th">Cập nhật</th>
					<th class="th">Xóa</th>
				</tr>	
			</thead>
			<tbody>
			<c:forEach items="${classes}" var="c" varStatus="status">
				<tr>
					<td class="td" style="width: 1em;"><input type="checkbox" name="checkItem" value="${f:keyToString(c.classKey)}" /></td>
					<td class="td"><c:out value="${(pageInfo.currentPage - 1) * pageSize + status.count}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.classId}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.className}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.subject.subjectId}" escapeXml="true" /></td>
					<td class="td"><c:out value="${c.lecturer.lecturerId}" escapeXml="true" /></td>
					<c:url value="/admin/updateClass/${f:keyToString(c.classKey)}.html" var="updateUrl">
						<c:param name="p" value="${pageInfo.currentPage}" />
						<c:param name="cId" value="${param.cId}" />
						<c:param name="sId" value="${param.sId}" />
						<c:param name="lId" value="${param.lId}" />
						<c:param name="semester" value="${param.semester}" />
					</c:url>
					<td class="td"><a href="${updateUrl}" class="updateLink"><img src="/images/update.png" width="15" height="15" /></a></td>
					<c:url value="/admin/deleteClass/${f:keyToString(c.classKey)}.html" var="deleteUrl">
						<c:param name="p" value="${pageInfo.currentPage}" />
						<c:param name="cId" value="${param.cId}" />
						<c:param name="sId" value="${param.sId}" />
						<c:param name="lId" value="${param.lId}" />
						<c:param name="semester" value="${param.semester}" />
					</c:url>
					<td class="td"><a href="${deleteUrl}" class="deleteLink"><img src="/images/delete.png" width="15" height="15" /></a></td>
				</tr>
			</c:forEach>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="8">
						<div class="pages">
							<t:paging pageInfo="${pageInfo}" link="/admin/searchClasses.html" params="${params}" />
						</div>
						<input type="submit" value="Xóa" id="deleteGroup" disabled="disabled" style="margin-top: 1em; width: 4em" />
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</c:if>